






//
//  RoomTypeTableview.m
//  住房条件帅选器
//
//  Created by MB__Lee on 2018/5/16.
//  Copyright © 2018年 MB__Lee. All rights reserved.
//

#import "RoomTypeTableview.h"
#import "RoomTypeCell.h"
#import "RoomTypeFooter.h"

@interface RoomTypeTableview()<UITableViewDelegate,UITableViewDataSource,RoomTypeFooterDelegate>

@property(nonatomic,strong)NSMutableArray *roomTypeMut; // 数据源

@property(nonatomic,strong)RoomTypeFooter *lastCell;//底部面积选择器

@end
static NSString *RoomTypeCell_Identi = @"RoomTypeCell";
static NSString *RoomTypeFooter_Identi = @"RoomTypeFooter";

@implementation RoomTypeTableview
-(NSMutableArray *)roomTypeMut{
    if (!_roomTypeMut) {
        _roomTypeMut = [NSMutableArray array];
        [_roomTypeMut addObjectsFromArray:@[@"全部",@"一室",@"两室",@"三室",@"四室",@"四室以上",@" "]];
        
    }
    return  _roomTypeMut;
}
-(RoomTypeFooter *)lastCell{
    if (!_lastCell) {
        _lastCell = [[NSBundle mainBundle] loadNibNamed:RoomTypeFooter_Identi owner:nil options:nil].lastObject;
        
        _lastCell.delegate = self;
    }
    return  _lastCell;
}

-(instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
    if (self = [super initWithFrame:frame style:style]) {
        [self registerNib:[UINib nibWithNibName:RoomTypeCell_Identi bundle:nil] forCellReuseIdentifier:RoomTypeCell_Identi];
        
        self.separatorStyle = UITableViewCellSeparatorStyleNone;
        self.delegate = self;
        self.dataSource = self;
        NSIndexPath *indexpath  =[NSIndexPath indexPathForRow:0 inSection:0];
        [self selectRowAtIndexPath:indexpath animated:YES scrollPosition:UITableViewScrollPositionNone];
        
        
    }
    return self;
}


#pragma mark -- tableview 代理方法、dataSource
-(NSInteger)numberOfSections{
    return  1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  self.roomTypeMut.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    RoomTypeCell *cell = [tableView dequeueReusableCellWithIdentifier:RoomTypeCell_Identi];
    cell.roomType = self.roomTypeMut[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (indexPath.row == self.roomTypeMut.count - 1) {
        [cell addSubview:self.lastCell];
        self.lastCell.frame = CGRectMake(0, 0, cell.bounds.size.width, cell.bounds.size.height);
    }
    
    return  cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([self.RTDelegate respondsToSelector:@selector(RoomTypeTableview:sendRoomType:)]) {
        [self.RTDelegate RoomTypeTableview:self sendRoomType:self.roomTypeMut[indexPath.row]];
    }
    
    
}

#pragma mark ---roomTypeFooter 代理方法
-(void)RoomTypeFooter:(RoomTypeFooter *)roomFooter sendMinSquare:(NSString *)minSquare maxSquare:(NSString *)maxSquare{
    if ([self.RTDelegate respondsToSelector:@selector(RoomTypeTableview:minSquare:maxSquare:)]) {
        [self.RTDelegate RoomTypeTableview:self minSquare:minSquare maxSquare:maxSquare];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
